import cv2
import numpy as np

img = cv2.imread('../images/flower.png')
h, w, _ = img.shape
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, img_binary = cv2.threshold(img_gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
print('阈值：', ret)

cv2.imshow('img', img)
cv2.imshow('img_gray', img_gray)
cv2.imshow('img_binary', img_binary)
cv2.waitKey(0)